﻿/************************************************************************
* Copyright (c) 2018 All Rights Reserved.
* 命名空间：ZTService.Bet
* 文件名：InitBet
* 创建人：David Rodríguez
* 创建时间：2018/8/3 星期五 15:45:19
* 描述：初始化系统
*************************************************************************/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DavidHelper;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using ZTService.Modle;

namespace ZTService.Bet
{
    public class InitBet
    {
        private static string SystemUrl = "https://www.yao678.com/index.php/api/wis/getAllSeller";
        private static string NumberUrl= "https://www.yao678.com/index.php/api/wis/getOdds";


        public static void InitBaby()
        {
            InitSystem();
            InitNumber();
        }

        private static void InitSystem()
        {
            var json = HttpHelper.Get(SystemUrl, null);
            var obj2 = (JArray)JsonConvert.DeserializeObject(json);
            Common.SystemList=new List<BetSystem>();
            for (var i = 0; i < obj2.Count; i++)
            {
                var s = new BetSystem()
                {
                    BetEncode = obj2[i]["seller_encode"].ToString()
                };
                Common.SystemList.Add(s);
            }
        }


        private static void InitNumber()
        {
            foreach (var s in Common.SystemList)
            {
                s.CqsscNumberDic = InitByKind(s.BetEncode,(int)KindId.重庆时时彩);
                s.Pk10NumberDic = InitByKind(s.BetEncode,(int)KindId.北京赛车);
            }    
        }

        private static Dictionary<string,string> InitByKind(string encode,int kindid)
        {
            var json = HttpHelper.Get($"{NumberUrl}?encode={encode}&kindid={kindid}",null);
            var obj2 = (JObject) JsonConvert.DeserializeObject(json);
            var dic=new Dictionary<string,string>();
            for (var i = 0; i < obj2["data"].Count(); i++)
            {
                dic.Add(obj2["data"][i]["de_label"].ToString(),obj2["data"][i]["de_id"].ToString());
            }
            
            return dic;
        }
    }
}